﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Navigation.Designer
{
	[TestClass]
	public class StateInfoTest
	{
		[TestMethod]
		public void AnBnC_Makes_1_Dialog()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnC.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(1, dialogs.Count());
		}

		[TestMethod]
		public void A_B_C_Makes_3_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("A_B_C.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(3, dialogs.Count());
		}

		[TestMethod]
		public void AnB_CnD_Makes_2_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnB_CnD.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(2, dialogs.Count());
		}

		[TestMethod]
		public void AnB_An1C_Makes_1_Dialog()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnB_An1C.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(1, dialogs.Count());
		}

		[TestMethod]
		public void AnB_CnB_Makes_3_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnB_CnB.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(3, dialogs.Count());
		}

		[TestMethod]
		public void AnbB_CnB_Makes_2_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnbB_CnB.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(2, dialogs.Count());
		}

		[TestMethod]
		public void AnbB_CnbB_Makes_2_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnbB_CnbB.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(2, dialogs.Count());
		}

		[TestMethod]
		public void AnbB_CnbB_Bi_Makes_3_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnbB_CnbB_Bi.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(3, dialogs.Count());
		}

		[TestMethod]
		public void AnBnCnA_Makes_1_Dialog_A()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnCnA.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(1, dialogs.Count());
			Assert.IsNotNull(dialogs.Where(d => d.Initial.Key == "A").FirstOrDefault());
		}

		[TestMethod]
		public void AnBnCnA_Bi_Makes_1_Dialog_B()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnCnA_Bi.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(1, dialogs.Count());
			Assert.IsNotNull(dialogs.Where(d => d.Initial.Key == "B").FirstOrDefault());
		}

		[TestMethod]
		public void AnBnCnDnB_Makes_1_Dialog()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnCnDnB.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(1, dialogs.Count());
		}

		[TestMethod]
		public void AnBnCnA_DnB_Makes_1_Dialog()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnCnA_DnB.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(1, dialogs.Count());
		}

		[TestMethod]
		public void AnBnbCnA_DnbB_Makes_1_Dialog()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnbCnA_DnbB.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(1, dialogs.Count());
		}

		[TestMethod]
		public void AnB_CnB_BnD_EnDnF_Makes_5_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnB_CnB_BnD_EnDnF.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(5, dialogs.Count());
		}

		[TestMethod]
		public void AnB_CnBnDnB_Makes_3_Dialogs_Not_D()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnB_CnBnDnB.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(3, dialogs.Count());
			Assert.IsNull(dialogs.Where(d => d.Initial.Key == "D").FirstOrDefault());
		}

		[TestMethod]
		public void AnbB_CnBnDnB_Makes_3_Dialogs_Not_B()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnbB_CnBnDnB.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(3, dialogs.Count());
			Assert.IsNull(dialogs.Where(d => d.Initial.Key == "B").FirstOrDefault());
		}

		[TestMethod]
		public void AnbB_CnBnDnB_Makes_3_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnbB_CnBnDnB.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(3, dialogs.Count());
		}

		[TestMethod]
		public void AnbB_CnBnbDnB_Makes_2_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnbB_CnBnbDnB.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(2, dialogs.Count());
		}

		[TestMethod]
		public void AnBnCnDnB_Cn1EnFnGnHnF_Makes_1_Dialog()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnCnDnB_Cn1EnFnGnHnF.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(1, dialogs.Count());
		}

		[TestMethod]
		public void AnBnCnAn1Cn1Bn1A_Makes_1_Dialog()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnCnAn1Cn1Bn1A.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(1, dialogs.Count());
		}

		[TestMethod]
		public void AnBnC_AiBi_Makes_2_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnC_AiBi.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(2, dialogs.Count());
		}

		[TestMethod]
		public void AnBnC_AiBiCi_Makes_3_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnC_AiBiCi.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(3, dialogs.Count());
		}

		[TestMethod]
		public void AnBnDnB_CnbD_Di_Makes_4_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnDnB_CnbD_Di.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(4, dialogs.Count());
		}

		[TestMethod]
		public void AnbBnbCnbDnbC_Bi_Makes_2_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnbBnbCnbDnbC_Bi.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(2, dialogs.Count());
		}

		[TestMethod]
		public void AnBnCnAn1Cn1Bn1An1C_Makes_1_Dialog()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnCnAn1Cn1Bn1An1C.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(1, dialogs.Count());
		}

		[TestMethod]
		public void AnBnCnAn1Cn1B_Ci_Makes_1_Dialog()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnCnAn1Cn1B_Ci.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(1, dialogs.Count());
		}

		[TestMethod]
		public void BnCnBn1A_Makes_1_Dialog()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("BnCnBn1A.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(1, dialogs.Count());
		}

		[TestMethod]
		public void BnCnBn1bA_DnA_EnA_Makes_4_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("BnCnBn1bA_DnA_EnA.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(4, dialogs.Count());
		}

		[TestMethod]
		public void AnBnCnC_Makes_1_Dialog()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnCnC.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(1, dialogs.Count());
		}

		[TestMethod]
		public void AnBnCnCn1A_Makes_1_Dialog()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnCnCn1A.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(1, dialogs.Count());
		}

		[TestMethod]
		public void AnbBnB_CnB_Makes_2_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnbBnB_CnB.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(2, dialogs.Count());
		}

		[TestMethod]
		public void AnBnB_CnB_Makes_3_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnB_CnB.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(3, dialogs.Count());
		}

		[TestMethod]
		public void AnBnbB_CnB_Makes_3_Dialogs()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnbB_CnB.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(3, dialogs.Count());
		}

		[TestMethod]
		public void AnBnCnDnBn1B_Cn1C_Makes_1_Dialog()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnBnCnDnBn1B_Cn1C.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(1, dialogs.Count());
		}

		[TestMethod]
		public void AnA_Makes_1_Dialog()
		{
			NavigationDiagram navigationConfiguration = NavigationUtility.LoadModel("AnA.navigation");
			List<Dialog> dialogs = new StateInfo().Convert(navigationConfiguration);
			Assert.IsTrue(NavigationUtility.ValidateNavigation(navigationConfiguration, dialogs));
			Assert.IsTrue(NavigationUtility.ValidateTransition(navigationConfiguration, dialogs));
			Assert.AreEqual(1, dialogs.Count());
		}
	}
}
